package com.clf.data.redis.core.json;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.parser.ParserConfig;
import org.springframework.data.redis.serializer.SerializationException;

/**
 * fastjson解析器，主要解析带有TypeReference的，也就是类似List《String》这样泛型嵌套的问题
* @author <a href="mailto:zhudelie@zuozh.com">zhudelie</a>
* @version 
* @since JDK 1.6
* create on 2017年3月31日
* Copyright 2017 ZZJR All Rights Reserved.
*
*/
public class FastJsonSerializerType<T> extends FastJsonSerializerAbstractor<T>{
	TypeReference<T> type;
	public FastJsonSerializerType(TypeReference<T> type) {
		this(type, true);
	}
	public FastJsonSerializerType(TypeReference<T> type, boolean autoRemove) {
		super(autoRemove);
		this.type = type;
	}

	@Override
	protected T deserialize0(byte[] bytes) throws SerializationException {
		return JSON.parseObject(bytes2String(bytes), type.getType(), ParserConfig.global, JSON.DEFAULT_PARSER_FEATURE);
	}

}
